<template>
  <div>
    <!-- 上面搜索的框 -->
    <table>
      <tr>
        <td>角色名称:</td>
        <td>
          <el-input size="small"></el-input>
        </td>
        <td>
          <el-button type="primary" class="el-icon-search" size="small">
            搜索
          </el-button>
        </td>
      </tr>
    </table>
    <!-- 数据渲染 -->
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="name" label="角色名称" width="180"> </el-table-column>
      <el-table-column prop="pid" label="角色编码" width="180"> </el-table-column>
      <el-table-column prop="address" label="配置"> 
          <el-button @click="setrespurce(1)">添加资源</el-button>
      </el-table-column>
    </el-table>
    <!-- 弹框 -->
    <el-dialog title="新增" :visible.sync="dialogTableVisible" width="90%">
       <el-transfer v-model="value" :data="data"></el-transfer>
    <el-button @click="setresource">确认</el-button>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
        tableData:[],
        multipleSelection:[],
        dialogTableVisible: false,
        value:[],
        data:[],
         form: {
          name: '',
          pid: '',
        },
        formLabelWidth: '120px',
        roleid:0,
    };
  },
  mounted() {
      this.goods()
  },

  methods: {
    goods(){
      this.axios.get('rbac/promitions/add/query?page=1&page_size=5').then((resp) => {
        console.log(resp)
        if(resp.data.code==200){
          this.tableData=resp.data.data.items   
        }
      })
    },
    setrespurce(roleid){
        // //获取二级资源列表
        this.roleid = roleid
        alert(roleid)
        this.axios.get('rbac/promitions/gettworesource').then((resp) => {
            console.log(resp.data.data.items)
            this.data=resp.data.data.items
        })
        //获取此角色已经配置的资源
          this.axios.get('rbac/promitions/getRoleResource?roleid='+roleid).then((resp) => {
            console.log(resp.data.data.items)
            this.value=resp.data.data.items
          })
        this.dialogTableVisible=true
    },
    //配制新的资源
      setresource(){
         this.axios.get("rbac/promitions/setResource?roleid="+this.roleid+"&idlist="+this.value).then(res=>{
          if(res.data.code==1001){
            console.log(res.data.msg)
          }else{
              this.dialogVisible = false
              console.log(res)
              this.roleid=0
              this.dialogTableVisible=false
          }
        
        })
      }
  }
};
</script>

<style scoped>
</style>
